home *** CD-ROM | disk | FTP | other *** search
/ MacGames Sampler / PHT MacGames Bundle.iso / MacSource Folder / Samples from the CD / Add-ons / CAfterDark20 / GlueCode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-02  |  2.4 KB  |  113 lines  |  [TEXT/KAHL]

  1. /*
  2.  * © Copyright Jeff Francis 1990
  3.  * All rights reserved
  4.  *
  5.  * $Id$
  6.  *
  7.  * Description - Contains the C main routine that glues together
  8.  * the default After Dark calling mechanism to an object/message
  9.  * based interface.  Page references are to "After Dark
  10.  * Programmer's Manual."
  11.  */  
  12.  
  13. #include <SetUpA4.h>
  14. #include <oops.h>
  15. #include "ADGMTypes.h"
  16. #include "GlueCode.h"
  17.  
  18. pascal OSErr main(Handle *storage, RgnHandle blankRgn, eMessage message, GMParamBlockPtr params)
  19. {
  20.     OSErr status = noErr;
  21.  
  22.     /*
  23.      * Setup THINK C's A4 global world.
  24.      */
  25.     RememberA0();
  26.     SetUpA4();
  27.     
  28.     /*
  29.      * If we've allocated storage then lock it down.
  30.      */
  31.     if (*storage != 0) {
  32.         MoveHHi(*storage);
  33.         HLock(*storage);
  34.     }
  35.     
  36.     switch (message) {
  37.     case kInitialize:
  38.         /*
  39.          * Create a new object and make storage point to it.  If
  40.          * the new fails then return with an error (Page 18 - Errors).
  41.          * If the new is successful, lock the object down because
  42.          * we wouldn't have locked it down before.  Finally, send
  43.          * the object an Initialize message.
  44.          */
  45.         if ((*storage = new(SUBCLASS)) == 0)
  46.             return kModuleError;
  47.         MoveHHi(*storage);
  48.         HLock(*storage);
  49.         status = ((CAfterDark *)*storage)->Initialize(blankRgn, params);
  50.         break;
  51.  
  52.     case kBlank:
  53.         /*
  54.          * Send a Blank message to the object.
  55.          */
  56.         status = ((CAfterDark *)*storage)->Blank(blankRgn, params);
  57.         break;
  58.  
  59.     case kDrawFrame:
  60.         /*
  61.          * Send a DrawFrame message to the object.
  62.          */
  63.         status = ((CAfterDark *)*storage)->DrawFrame(blankRgn, params);
  64.         break;
  65.     
  66.     case kClose:
  67.         /*
  68.          * Send a Close message to the object, delete it and then
  69.          * set storage to NIL.
  70.          */
  71.         status = ((CAfterDark *)*storage)->Close(blankRgn, params);
  72.         delete(*storage);
  73.         *storage = 0;
  74.         break;
  75.     
  76.     default: /* kButtonMessage */
  77.         /*
  78.          * If we have a ButtonMessage, then send the object the
  79.          * ButtonMessage.
  80.          */
  81.         if (message >= kButtonMessage)
  82.             status = ((CAfterDark *)*storage)->ButtonMessage(blankRgn, params, message);
  83.         break;
  84.     
  85.     case kModuleSelected:
  86.         /*
  87.          * Send a ModuleSelected message to the object.
  88.          */
  89.         status = ((CAfterDark *)*storage)->ModuleSelected(blankRgn, params);
  90.         break;
  91.         
  92.     case kDoHelp:
  93.         /*
  94.          * Send a DoHelp message to the object.
  95.          */
  96.         status = ((CAfterDark *)*storage)->DoHelp(blankRgn, params);
  97.         break;
  98.     }
  99.     
  100.     /*
  101.      * If we've allocated storage then we should unlock what we've
  102.      * previously locked.
  103.      */
  104.     if (*storage != 0)
  105.         HUnlock(*storage);
  106.         
  107.     /*
  108.      * Restore THINK C's A4 global environment.
  109.      */
  110.     RestoreA4();
  111.     
  112.     return status;
  113. }